<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%
String path = request.getContextPath();
request.setCharacterEncoding("UTF-8");
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">   
<head>
<base href="<%=basePath%>">
<title>对账管理</title>
<jsp:include page="/WEB-INF/jsp/common/common.jsp"></jsp:include>	
<link href="css/calendar.css"  rel="stylesheet" type="text/css" >
	<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css">
	<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.5.js"></script>
	<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.5.js"></script>
	<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
	<script language="javascript" type="text/javascript">
		history.forward();
		$(document).ready(function() {
			isReadyIframe();
			loadPrivilegeBranch();
// 			queryTrans();
			
			<% if(request.getAttribute("appException") != null){
				String appException = (String)request.getAttribute("appException");
			%>
				
				$("#manualReconciliationDiv").OpenDiv();
				$.message("error","<%=appException%>");
				
			<% } 
			
			 if(request.getAttribute("total") != null){
			%>
			 $("#manualReconciliationDiv").OpenDiv();
			 $("#reconciliationResultDiv").css("display","block");
			 
			 $("#manualReconciliationDiv").css("height","40%");
			<% } %>
		});
		
		function isReadyIframe(){
			var iframe = $(window.parent.document).find("#iframe").length;
			if(iframe==0){
				window.location.href="<%=basePath%>index.jsp";
			}
		}
		var defaultBranchCode = "";
		//加载app下拉框
		function loadPrivilegeBranch(){
			$.ajax({
					url : "<%=path%>/dataManage/queryPrivilegeBranch",
					type : 'POST',
					async : false,
					dataType:'json',
					success : function(data) {
						if(data){
							if($.validate(data))return;
							//业务处理
							//接口下拉框对象
							var appSelect = document.getElementById("privilegeBranch");
							if (data != null) {
								appSelect.length=0;
								if(data.length>0){
									defaultBranchCode = data[0].deptCode;
								}
								for (var i = 0; i < data.length; i++) {
									var option = new Option();
									option.text = data[i].deptCname;
									option.value = data[i].deptCode;
									option.title = data[i].deptCname;
									appSelect.add(option);
								}
							}
						}
					}
				});
		 }
		//清空相关联数据
		function clearReleFiled(){
			$("#instCode").val("");
			$("#prodInstCode").val("");
			$("#dptCode").val("");
		}
		//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
		function bindradio(){
			$("input[name='prodradio']").click(function(){
				$("input[name='prodradio']").parent().parent().removeClass("table_highlighter");
				$(this).parent().parent().addClass("table_highlighter");
		   	});
			$("input[name='partnerradio']").click(function(){
				$("input[name='partnerradio']").parent().parent().removeClass("table_highlighter");
				$(this).parent().parent().addClass("table_highlighter");
		   	});
			$("input[name='deptradio']").click(function(){
				$("input[name='deptradio']").parent().parent().removeClass("table_highlighter");
				$(this).parent().parent().addClass("table_highlighter");
		   	});
		}
		
		//“重置”查询条件
		function  resetCriteria(){
			$("#privilegeBranch").val(defaultBranchCode);
			$("#instCode").val("");
			$("#prodInstCode").val("");
			$("#dptCode").val("");
			$("#polno").val("");
			$("#confirmno").val("");
			$("#checkSelect").val("");
			$("#trxdateBegin").val("");
			$("#trxdateEnd").val("");
			$("#subPartnerNo").val("");
		}
		function reconclick(obj,flag){
			var contr = $(obj).parent('td').parent('tr')[0];
			var polNo=contr.childNodes[4].innerHTML;
			var content='请确认是否修改'+polNo+'保单的对账状态？';
			if(flag==2){
				content='请确认是否修改'+polNo+'批单的对账状态？';
			}
			$.dialog({
				type: "warn",
				content:content ,
				onOk: function() {
					$.openLoading();
					var editTr = $(obj).parent('td').parent('tr')[0];
					/**获取transid**/
					var transId=editTr.childNodes[0].innerHTML;
					$.ajax({
						url : "<%=path%>/dataManage/reconciled",
						type : 'POST',
						async : false,
						data:{transid:transId},
						dataType:'json',
						success : function(data) {
							$.closeLoading();
							if(data.result=='success'){
								$.message("success",data.result.message);
								$(obj).parent().parent().children(" td:eq(9)").html('已对账')
								$(obj).parent('td').html('');
							}else{
								$.message(data.result,data.result.message);
							}
						}
					});
				}
			});
		}
		//点击“查询”
		function queryTrans(pageIndex){
			
			if(pageIndex == null){
				pageIndex = 1;
			}
			var asyncFlag = true;
			if(pageIndex == -1){
				pageIndex = 1;
				asyncFlag = false;
			}
			
			var branchCode = $("#privilegeBranch").val();
			var channelCode = $("#instCode").val();
			var planCode = $("#prodInstCode").val();
			var subDeptCode = $("#dptCode").val();
			var checkFlag= $("#checkSelect").val();
			var polno= $.trim($("#polno").val());
			var confirmno=  $.trim($("#confirmno").val());
			var trxdateBeginStr =$("#trxdateBegin").val();
			var trxdateEndStr =$("#trxdateEnd").val();
			var subPartnerNo= $.trim($("#subPartnerNo").val());//合作伙伴子机构
			
			if(trxdateBeginStr != null && "" != trxdateBeginStr){
				var trxdateBegin = new Date(trxdateBeginStr);
				
				if(trxdateBegin > new Date()){
					$.message("error","交易起期不能大于当前日期");
					return;
				}
				
				if(trxdateEndStr != null && "" != trxdateEndStr){
					var trxdateEnd = new Date(trxdateEndStr);
					
					if(trxdateEnd > new Date()){
						$.message("error","交易止期不能大于当前日期");
						return;
					}
					
					if(trxdateBegin > trxdateEnd){
						$.message("error","交易起期不能大于交易止期");
						return;
					}else if((trxdateEnd - trxdateBegin) > 30*24*60*60*1000){
						$.message("error","交易起期与交易止期之间的时间跨度不能大于30天");
						return;
					}
				}
			}
			$.openLoading();
			$.ajax({
				url : "<%=path%>/dataManage/queryTransByCriteria",
				type : 'POST',
				async : asyncFlag,
				dataType:'json',
				data:{
					brachCode:branchCode,
					channelCode:channelCode,
					planCode:planCode,
					subDeptCode:subDeptCode,
					checkFlag:checkFlag,
					polno:polno,
					confirmno:confirmno,
					trxdateBegin:trxdateBeginStr,
					trxdateEnd:trxdateEndStr,
					pageIndex:pageIndex,
					subPartnerNo:subPartnerNo
				},
				success:function(data){
					$.closeLoading();
					if($.validate(data.page))return;
					//业务处理
					if(null != data){
						<%--var buttonStr = "<a href='' onClick='updateTrans(this);return false'>维护</a>";--%>
						var fieldNames = "TRANSID@TDH,CHANNEL_NAME,TRXDATESTR,TRANS_NAME,POLNO,CONFIRMNO,PREMIUM,AGENTFEE,STARTTIMESTR,CHECK_FLAG?[{'-1':'无需对账'};{'1':'已对账'};{'0':'未对账'};{'2':'对账失败'};{'3':'未知数据'}],SHOWBUTTON";
						//console.info(data);
						var tableContent = creatTable1(fieldNames,data.page,null);
						var tableObj = $("#transTable");
						tableObj.find("tbody").remove();
						tableObj.append(tableContent);
						
						$("#count").text(data.page.total);//设置记录数
						$("#agentfee").text(data.agentfee);//设置手续费合计
						$("#premium").text(data.premium);//设置保费合计
						
						var strPage = creatChannelPage(pageIndex,6,data.page.maxPage,"3");
						var pageDIV = $("#transPageDiv");
						pageDIV[0].innerHTML="";
						pageDIV.append(strPage); 
						
						if(!asyncFlag){
							if(data.page.data == null || data.page.data.length == 0){
								$.message("error","对账导出数据为空");
								return;
							}
							
							$("#downloadTransFileForm").attr("action","<%=path%>/dataManage/downloadTransFile");
						 	$("#downloadTransFileForm").submit();
						}
						sysDate=data.sysdata;
					}
				}
			});
		}
		
		//------------------------------------------ 出单机构 开始----------------------------------------------
		//打开机构窗口
		function openDeptDiv(pageIndex,obj){
			
			if($.trim($('#privilegeBranch').val()).length==0){
				$.message("error", "请先选择机构");
				return;
			}
			
			$('#deptcode').val('');
			$('#deptcnname').val('');
			$("#"+obj.id).blur();
			queryCoreDept(pageIndex);
		}

		//调用拼接参数的方法，并执行查询
		function queryCoreDept(pageIndex){
			var size = 8;
			var code = $.trim($('#deptcode').val());
			var name = $.trim($('#deptcnname').val());
			var pno =  $.trim($('#privilegeBranch').val());
			queryAllDepts({size:size,pageIndex:pageIndex,deptCode:code,deptCNname:name,parentCode:pno});
		}


		//查询机构
		function queryAllDepts(param){
			$.openLoading();
			$.ajax({
				url : "dataManage/loadCoreDept",
				type : 'POST',
				async : true,
				data:param,
				dataType:'json',
				success:function(deptPage){
					$.closeLoading();
					if($.validate(deptPage))return;
							var radioObj ="<input class='input_fxk' name='deptradio' type='radio' value=''>";
							var fieldNames = "deptCode,deptCNname";
							var tableContent = creatTable1(fieldNames,deptPage,radioObj);
							var tableObj = $("#deptTable");
							tableObj.find("tbody").remove();
							tableObj.append(tableContent);
							
							var strPage = creatChannelPage3(param.pageIndex,6,deptPage.maxPage,"18");
							var pageDIV = $("#deptPageDIV");
							pageDIV[0].innerHTML="";
							pageDIV.append(strPage);
							
							$("#deptDiv").OpenDiv();
							
							bindradio();
					}
			});
		}

		//点击“确定” ，选择 出单机构
		function chooseDept(){
			var selectedDept= $("input[name='deptradio']:checked");
			if(selectedDept.length==0){
				$.message("error", "请选择一个出单机构");
				return;
			}
			var deptCode = selectedDept.parent().parent().children(" td:eq(1)").html();
			$('#dptCode').val(deptCode);
			closeCurrentDIV('deptDiv');
		}

		//------------------------------------------ 出单机构 结束----------------------------------------------
		//------------------------------------------ 合作伙伴 开始----------------------------------------------
//initTradPartners
function queryPartner(param){
	$.openLoading();
	$.ajax({
		url : "dataManage/loadChannelInfoByAppid",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(partnerPage){
			$.closeLoading();
			if($.validate(partnerPage))return;
			var radioObj ="<input class='input_fxk' name='partnerradio' type='radio' value=''>";
			var fieldNames = "channelCode,channelName";
			var tableContent = creatTable1(fieldNames,partnerPage,radioObj);
			var tableObj = $("#TradPartnerTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			
			var strPage = creatChannelPage2(param.pageIndex,6,partnerPage.maxPage,"16");
			var pageDIV = $("#TradPartnerPageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			
			$('#tradPartnerDiv').OpenDiv();
			
			bindradio();
			}
	});
}  



//打开合作伙伴 div 方法
function openThisDiv(divObj,pageIndex,obj){
	if(($.trim($('#privilegeBranch').val())).length==0){
		$.message('error',"请先选择机构");
		return;
	}
	$('#channelCode').val('');
	$('#channelName').val('');
	$("#"+obj.id).blur();
	queryTradPartners(pageIndex);
}


//拼接页面查询参数  查询合作伙伴
function mergePartnerParams(pageIndex){
	var size = 8;
	var deptCode = $.trim($('#privilegeBranch').val());
	var channelCode = $.trim($('#channelCode').val());
	var channelName = $.trim($('#channelName').val());

	queryPartner({pageIndex:pageIndex,size:size,deptCode:deptCode,channelCode:channelCode,channelName:channelName});
}



//查询 合作伙伴
function queryTradPartners(pageIndex){
	mergePartnerParams(pageIndex);
}


//点击“确定”按钮，选择合作伙伴
function choosePartner(){
	var selectedPartner = $("input[name='partnerradio']:checked");
	if(selectedPartner.length==0){
		$.message("error", "请选择一个合作伙伴");
		return;
	}
	var pno = selectedPartner.parent().parent().children(" td:eq(1)").html();
	$('#instCode').val(pno);
	$("#prodInstCode").val("");//清空投保方案字段
	
	closeCurrentDIV('tradPartnerDiv');
}
//------------------------------------------ 合作伙伴 结束----------------------------------------------
//------------------------------------------ 投保方案  开始----------------------------------------------
//打开产品窗口
function openProdDiv(pageIndex,obj){
	if(($.trim($('#instCode').val())).length==0){
		$.message('error',"请先选择合作伙伴");
		return;
	}
	$('#planCode').val('');
	$('#planName').val('');
	$("#"+obj.id).blur();
	queryTradProdInst(pageIndex);
}

//调用拼接参数的方法，并执行查询
function queryTradProdInst(pageIndex){
	var size = 8;
	var code = $.trim($('#planCode').val());
	var desc = $.trim($('#planName').val());
 	var channelCode = $.trim($('#instCode').val());
	queryAllProds({size:size,pageIndex:pageIndex,planCode:code,planName:desc,channelCode:channelCode});
}


//查询产品
function queryAllProds(param){
	$.openLoading();
	$.ajax({
		url : "dataManage/loadInsurePlan",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(partnerPage){
			$.closeLoading();
					var radioObj ="<input class='input_fxk' name='prodradio' type='radio' value=''>";
					var fieldNames = "PLANCODE,PLANNAME";
					var tableContent = creatTable1(fieldNames,partnerPage,radioObj);
					var tableObj = $("#productTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage(param.pageIndex,6,partnerPage.maxPage,"17");
					var pageDIV = $("#productPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$("#prodPlanDiv").OpenDiv();

					bindradio();
			}
	});
}

//点击“确定” ，选择 产品

function chooseProd(){
	var selectedProd= $("input[name='prodradio']:checked");
	if(selectedProd.length==0){
		$.message("error", "请选择一个投保方案");

		return;
	}
	
	var prodCode = selectedProd.parent().parent().children(" td:eq(1)").html();//产品代码
	$('#prodInstCode').val(prodCode);
	
	closeCurrentDIV('prodPlanDiv');
}
//------------------------------------------ 投保方案  结束----------------------------------------------

//统一 关闭  窗口
function closeCurrentDIV(obj){
		$("#"+obj).CloseDiv();	
}
		//模板下载
        function downloadReconciliationMould(){
   		 	window.location.href='<%=path%>/dataManage/downloadReconciliationMould';
   	   }
		
       //手动对账
		function manualReconciliation(){
			$("#manualReconciliationDiv").OpenDiv();
		} 
       
       //隐藏“手动对账”（选择文件）窗口
		function closeManualReconciliationDiv(){
			$("#manualReconciliationDiv").CloseDiv();
			$("#reconciliationResultDiv").css("display","none");
		}
       
		//选择对账对账文件层，点击“对账”
		function reconciliationFileChose(){
			
			var reconciliationFile = $("#reconciliationFile").val();
			if(reconciliationFile.length == 0){
				$.message("error", "请先选择对账文件");
				return;
			}  
			
			if(reconciliationFile.substr(reconciliationFile.lastIndexOf(".")) != ".xls"){
				$.message("error", "必须选择xls格式的对账文件");
				return;
			}
			
			$("#chooseReconciliationFileForm").attr('action','<%=path%>/dataManage/manualReconciliation');
			$("#chooseReconciliationFileForm").submit(); 
		}
		
		//点击文件下载
		function downloadTransFile(){
			queryTrans(-1);
		}
		
		//------------------------------------------ 合作伙伴子机构 开始----------------------------------------------
		//加载subChannelTree
		function openSubChannelTreeDiv(){
			var partnerNo = $.trim($('#instCode').val());
			if(partnerNo.length==0){
				$.message("error", "请先选择合作伙伴");
				return;
			}
			
			$.openLoading();
			$.ajax({
				url : "<%=path%>/lifePolicyList/querySubChannelTree?"+new Date().getTime(),
				type : 'POST',
				async : true,
				data:{
					parentChannelCode:partnerNo
				},
				dataType:'json',
				success:function(data){
					$.closeLoading();
					if($.validate(data))return;
					
					if(data.length == 0){
						$.message("error", "所选合作伙伴下没有合作伙伴子机构");return;
					}
					var setting = {
							check: {
								enable: true,
								chkStyle: "radio",
								radioType: "all"
							},
							data: {
								simpleData: {
									enable: true
								}
							}
						};

					$.fn.zTree.init($("#subChannelTree"), setting, data);
					
					$("#subChannelTreeDiv").OpenDiv();
				}
			});
		}
		
		//点击“确定”按钮，选择合作伙伴子机构
		function chooseSubPartner(){
			var subChannelTree = $.fn.zTree.getZTreeObj("subChannelTree");
			if(subChannelTree.getCheckedNodes(true).length==0){
				$.message("error", "请选择一个合作伙伴子机构");
				return;
			}
			var subChannels = subChannelTree.getCheckedNodes(true);
			$("#subPartnerNo").val(subChannels[0].id);
			
			closeCurrentDIV('subChannelTreeDiv');
		}
		var sysDate='';
		/**保单注销*/
		function policyCancel(obj,flag){
		
			if(sysDate){
				 var date = new Date(sysDate)
				 var contr = $(obj).parent('td').parent('tr')[0];
				var startdate=contr.childNodes[8].innerHTML;
				var polNo=contr.childNodes[4].innerHTML;
				 var startTime = new Date(startdate);
                 var content="是否确认对该保单"+polNo+"进行注销操作？"
				 if(startTime.getTime()<=date.getTime()){
					 content="该保单"+polNo+"已起保，是否确认进行注销操作？"
				 }
				 $.dialog({
						type: "warn",
						content:content ,
						onOk: function() {
							$.openLoading();
							var editTr = $(obj).parent('td').parent('tr')[0];
							/**获取transid**/
							var transId=editTr.childNodes[0].innerHTML;
							$.ajax({
								url : "<%=path%>/dataManage/policyCancel",
								type : 'POST',
								async : false,
								data:{transid:transId},
								dataType:'json',
								success : function(data) {
									$.closeLoading();
									if(data.result=='success'){
										$.message("success",data.message);
										/* queryTrans(); */
									}else{
										$.message(data.result,data.message);
									}
								}
							});
						}
					});
			}
		}
	</script>
	
	</head>
	<body>
 	 <div class="current">
           <table class="current_table_1">
             <tbody>
              	<tr class="f2">
	                <td><img src="./images/current_1.jpg"></td>
	                <td class="current_table_1_td">
	                  <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
	                  <span style=" color:#136bab; ">统计分析
	                  	<span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>对账管理
	                  </span>
                  	</td>
                 	<td><img src="./images/current_3.jpg"></td>
              	</tr>
           	 </tbody>
           </table>
     </div>
       
       <!--查询条件及结果表单 -->
        <table border="1" class="table_02" style="height:150px">
	  		<tr height="50px">
	  			<td colspan="2" align="center">
	  				<form method="post" id="downloadTransFileForm" action=""> 
						<table border="0" style="margin: 12px auto;">
							<tr>
								<td style="padding-left:40px; border: 0;text-align: right" nowrap="nowrap">机构：</td>
								<td style="border: 0;text-align: left;padding-right: 60px">
								   <select class="search_select_1" name="privilegeBranch" id="privilegeBranch" onchange="clearReleFiled()" style="width: 206px">
					            		<option value="">--请选择--</option>
							  	   </select>&nbsp;<span class="red">*</span>
								</td>
								<td style="border: 0;text-align: right" nowrap="nowrap">合作伙伴：</td>
		                        <td style="border: 0 ;text-align: left; padding-right: 60px"><input name="instCode" id="instCode" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text">&nbsp;&nbsp;<input type="button"  class="input_button_5"  id="searchPartnerBtn" value="请选择" onClick="openThisDiv('tradPartnerDiv',1,this)"/></td>
								<td style="border: 0;text-align: right" nowrap="nowrap">合作伙伴子机构：</td>
		                        <td style="border: 0 ;text-align: left; padding-right: 60px"><input name="partnerSubCode" id="subPartnerNo" readonly="readonly" style=" background-color: #ccc;" class="input_text">&nbsp;&nbsp;<input type="button"  class="input_button_5"  id="searchSubPartnerBtn" value="请选择" onClick="openSubChannelTreeDiv()"/></td>
							</tr>
							<tr>
								<td style="border: 0; text-align: right" nowrap="nowrap">投保方案：</td>
								<td style="border: 0;text-align: left;padding-right: 60px">
								<input name="prodInstCode" id="prodInstCode" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text">&nbsp;<input type="button"  class="input_button_5" id="searchProdBtn" value="请选择" onClick="openProdDiv(1,this)"/></td>
								<td style="padding-left:40px;border: 0;text-align: right" nowrap="nowrap">出单机构：</td>
		                  		<td style="border: 0;text-align: left;padding-right: 60px"><input id="dptCode" name="dptCode" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text">&nbsp;&nbsp;<input type="button"  class="input_button_5" id="searchDeptBtn" value="请选择" onClick="openDeptDiv(1,this)"/></td>
								<td style="border: 0;text-align: right;" nowrap="nowrap">保单号：</td>
								<td style="border: 0;text-align: left;padding-right: 60px">
									<input name="polno" id="polno" class="input_text" style="width:130px;" size="25"/>
								</td>
							</tr>
							<tr>
								<td style="border: 0;text-align: right;" nowrap="nowrap">批单号：</td>
								<td style="border: 0;text-align: left;padding-right: 60px">
									<input name="confirmno" id="confirmno" class="input_text" style="width:130px;" size="25"/>
								</td>
								<td style="padding-left:40px;border: 0;text-align: right;" nowrap="nowrap">对账状态：</td>   
								<td style="border: 0;text-align: left;padding-right: 60px">
									<select name="checkSelect" class="search_select_1" id="checkSelect"">
						            	<option value="">--请选择--</option>
						            	<option value="-1">无需对账</option>
						            	<option value="0">未对账</option>
						            	<option value="1">已对账</option>
						            	<option value="2">对账失败</option>
						            	<option value="3">未知数据</option>
									</select>
								</td>
								<td style="border: 0;text-align: right;" nowrap="nowrap">交易起期：</td>
								<td style="border: 0;text-align: left;padding-right: 60px">
									 <input id="trxdateBegin" name="trxdateBegin" readonly="readonly" onclick="showCalendar('trxdateBegin','y-mm-dd');"  class="input_time"/>
								</td>					
							</tr>
							<tr>
								<td style="border: 0;text-align: right;" nowrap="nowrap">交易止期：</td>
								<td style="border: 0;text-align: left;padding-right: 60px">
									 <input id="trxdateEnd" name="trxdateEnd" readonly="readonly" onclick="showCalendar('trxdateEnd','y-mm-dd');"  class="input_time"/>
								</td>
							</tr>
							
							<tr>
								<td colspan="6" style="border: 0;padding-top: 5px;padding-right: 60px">
									<input type="button"  class="input_button_1"  value="查询"    onClick="queryTrans()"/>
								    <input type="button"  class="input_button_1"  value="导出" onClick="downloadTransFile()"/>
								   	<input type="button"  class="input_button_1"  value="重置"    onClick="resetCriteria()"/>
								</td>
							</tr>
						</table>	  				
					   
				    </form>
				</td>
	  		</tr>
	  		<tr>
	  			<td valign="top">
		  			<div id="transDiv" style="width:98%;margin:5px" >
		  				<div align="left" style="margin:15px">
			  				<input type="button"  class="input_button_2"  value="对账模板下载" onClick="downloadReconciliationMould()"/>
							<input type="button"  class="input_button_2"  value="手动对账" onClick="manualReconciliation()"/>
							<div align="right" style="margin:15px">
								<span>记录数：</span><a id="count" style="color: red">0</a>笔&nbsp;&nbsp;
								<span>含税保费合计：</span><a id="premium" style="color: red">0</a>元&nbsp;&nbsp;
								<span>手续费合计：</span><a id="agentfee" style="color: red">0</a>元&nbsp;&nbsp;
							</div>
				  		</div>
				  		<table class="table_02" id="transTable">
					  		<thead>
				               <tr>
				                  <th nowrap="nowrap">合作伙伴</th>
				                  <th nowrap="nowrap">交易日期</th>
				                  <th nowrap="nowrap">交易名称</th>
				                  <th nowrap="nowrap">保单号</th>
				                  <th nowrap="nowrap">批单号</th>
				                  <th nowrap="nowrap">含税保费</th>
				                  <th nowrap="nowrap">手续费</th>
				                  <th nowrap="nowrap">生效日期</th>
				                  <th nowrap="nowrap">对账状态</th>
				                  <th nowrap="nowrap" style="width: 130px">操作</th>
				             	<!--<th style="width:6%">操作</th>  -->  
				              	</tr>
				              </thead>
			              <tbody>
						  </tbody>
			            </table>
		  				 <div id="transPageDiv"  class="page"></div>
		  			</div>
	  			</td>
	  		</tr>
	  	</table>
       
       <!--手动对账窗口  -->
        <div id="manualReconciliationDiv"  style="display:none;width:50%;height: 30%">
        	<div class="table_title_div"">
				<table class="table_title" style="width:100% ;height: 20px;">
					<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeManualReconciliationDiv()"/></td>
					</tr>
				</table>
			</div>
			
	   		<form id="chooseReconciliationFileForm" action="" method="POST" enctype="multipart/form-data">
	     		<table class="table_02" style="width: 92%" align="center">
	     			<tr>
	     				<td style="padding:25px 20px ">
	     					请选择对账文件：<input type="file" id="reconciliationFile" name="reconciliationFile"/>
	        				<input type="button" class="input_button_1" value="对账" onClick="reconciliationFileChose()"/>
	     				</td>
	     			</tr>
	     		</table>
	     	</form>
	     	
	     	<div id="reconciliationResultDiv" style="display: none;margin-left: 40px;margin-bottom: 13px;font-size: 16px">
        		<table height="60px" width="150px">
        			<tr>
        				<th>对账总数：</th>
        				<td><font color="blue">${total}</font>笔</td>
        			</tr>
        			<tr>
        				<th>对账成功：</th>
        				<td><font color="green">${success}</font>笔</td>
        			</tr>
        			<tr>
        				<th>对账失败：</th>
        				<td><font color="red">${error}</font>笔</td>
        			</tr>
        		</table>
        	</div> 
        </div>
        <!--选择 合作伙伴 div-->
  		<div id="tradPartnerDiv" style="display:none;width:80%;">
  		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('tradPartnerDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="height:180px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
							 合作伙伴代码：<input name="txt3"  id="channelCode"  type="text" class="input_text" value="" >&nbsp;&nbsp;
							 合作伙伴名称：<input name="txt3" id="channelName"  type="text" class="input_text" value="">&nbsp;&nbsp;
								       <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryTradPartners(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="TradPartnerTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="TradPartnerPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn" value="确定" onclick="choosePartner()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeCurrentDIV('tradPartnerDiv')" class="input_button_3"/>
		</div>
	</div>
	
	<!--出单机构 DIV 默认隐藏-->
	<div id="deptDiv" style="display:none;width:80%;">
  		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('deptDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="height:180px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
							 出单机构代码：<input name="txt3"  id="deptcode"  type="text" class="input_text" value="" >&nbsp;&nbsp;
							 出单机构名称：<input name="txt3" id="deptcnname"  type="text" class="input_text" value="">
								       <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryCoreDept(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="deptTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:40%">出单机构代码</th>
			                  <th style="width:55%">出单机构名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="deptPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn" value="确定" onclick="chooseDept()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeCurrentDIV('deptDiv')" class="input_button_3"/>
		</div>
	</div>
	
	<!-- 投保方案 DIV 默认隐藏-->
  	<div id="prodPlanDiv"  style="display:none;width:80%;">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
				<div class="table_title_div">
					<table class="table_title" style='width:100%;height:20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('prodPlanDiv')"/></td>
						</tr>
					</table>
				</div>
	
			<!-- 修改id 名 -->
			<table class="table_02" id="addtempletTable" align="center" >
				<tbody>
				<tr>
				<td>
					<table class="search_table">
					<tr height="30px" >
							<td style="border:0px;text-align: right;">交易系统投保方案代码：</td>
							<td style="border:0px;text-align: left;">
								<input name="txt3"  id="planCode"  type="text" class="input_text" value="" style="width:120px;">
							</td>
							<td style="border:0px;text-align: right;">
								交易系统投保方案名称：
							</td>
							<td style="border:0px;text-align: left;"><input name="txt3" id="planName"  type="text" class="input_text" value="" style="width:120px;">
							 &nbsp;&nbsp;&nbsp;&nbsp;
							<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryTradProdInst(1)"/></td>
					</tr>
				</table>
				</td></tr>
					<tr>
						<td>
							<!-- 修改数据table名 -->
							<table id="productTable"  class="content_table_1">
								<thead>
									<tr class="f1">
					                  <th style="width:5%">选择</th>
					                  <th style="width:45%">交易系统投保方案代码</th>
					                  <th style="width:50%">交易系统投保方案名称</th>
					              	</tr>
								</thead>
								<!-- 修改tobody 默认为空 -->
								<tbody>
								</tbody>
							</table>
							<!-- 修改分页编码id 名  默认为空-->
							<div id="productPageDIV" class="page">
							</div>
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center" >
			 <input class="input_button_3" name="" type="button" onclick="chooseProd()" value="确定">&nbsp;&nbsp;
	         <input class="input_button_3" name="" type="button" onclick="closeCurrentDIV('prodPlanDiv')" value="取消">
			</div>
	   </div>
        
<%---------------------------------- 		

	<style>
		#updateTransDiv{
			position: absolute;
            width: 1000px;
            height: 140px;
            font-size: 12px;
            background: #fff;
            border: 2px solid #000;
            z-index: 2;
            display: none;
		} 
	</style>

	<script>
	
		//维护
		var checkFlag_original;//用于记录修改之前的对账状态
		function updateTrans(param){
			if(param){
				var transid=$(param).parent().parent()[0].childNodes[0].innerHTML;
				var polno=$(param).parent().parent()[0].childNodes[4].innerHTML;
				var transName=$(param).parent().parent()[0].childNodes[3].innerHTML;
				var checkFlag = $(param).parent().parent()[0].childNodes[9].innerHTML;
				checkFlag_original = checkFlag;

				$("#transid").val(transid);
				$("#polno_update").html(polno);
				$("#transName_update").html(transName);
				//$("#checkFlag").filter("option[text='未对账']").attr("selected",true);

				$("#checkFlag option").each(function () {   
                    if($(this).text() == checkFlag)  
                      $(this).attr("selected", "selected");  
                });  

				$("#updateTransDiv").OpenDiv();
			}
		}
         
		function  saveCheckFlagUpdated(){
			var transid = $("#transid").val();
			var checkFlag = $("#checkFlag").val();
			var checkFlag_str = $("#checkFlag").find("option:selected").text();

			if(checkFlag==""){
				$.message("error", "请选择对账状态");
				return;
			}
			
			if(transid==""){
				$.message("error","系统出现异常，请联系管理员");
				return;
			}
			
			if(checkFlag_str == checkFlag_original){
				$.message("error","您还没有做任何修改");
				return;
			}
			
			$.dialog({
				type: "warn",//success,error
				content: '您确定要将这条记录的对账状态由“'+checkFlag_original+'”修改为“'+checkFlag_str+'”吗？',
				onOk: function() {
					$.openLoading();
					$.ajax({
						   url:"<%=path%>/gatewayTrans/editGatewayTrans",
						   type:'POST',
						   async:true,
						   dataType:'json',
						   data:{
							   transid:transid,
							   checkFlag:checkFlag
						   },
					      success:function(updateResult){
					    	  $.closeLoading();
					    	  
					    	  if($.validate(updateResult))return;
					    	  
						    	  closeUpdateTransDiv();
						    	  queryTrans(1);
					      }
					});
				}
			});

		}
		
		function closeUpdateTransDiv(){
			$("#updateTransDiv").CloseDiv();
		}
	
	</script>


	<!--维护表单 -->
		<div id="updateTransDiv">  
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeUpdateTransDiv()"/></td>
						</tr>
					</table>
			</div>
			
			<input type="hidden" id="ifindex" value="">
			<table class="table_02" style="height:100px" align="center" >
				<tr>
					<td>
						保单号：<span id="polno_update"></span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						交易类型：<span id="transName_update"></span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						对账状态：<select class="search_select_1" id="checkFlag">
					            	<option value="">--请选择--</option>
					            	<option value="-1">无需对账</option>
					            	<option value="0">未对账</option>
					            	<option value="1">已对账</option>
					            	<option value="2">对账失败</option>
					            	<option value="3">未知数据</option>
						</select>&nbsp;&nbsp;&nbsp;
						<input type="hidden" id="transid" value=""/>
						<input  class="input_button_1" type="button" value="更改" onclick="saveCheckFlagUpdated();"/>&nbsp;&nbsp;&nbsp;
					</td>
				</tr>
			</table>
		</div>	
 ------------------------------------------%>
 
 	<%--subChannelTree(选择合作伙伴子机构层) --%>
    <div id="subChannelTreeDiv" style="display: none;width:500px;margin-top: -50px" align="center">
    	<div class="table_title_div">
			<table class="table_title" style='width:500px; height: 20px;'>
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeChannelTreeDiv()"/></td>
				</tr>
			</table>
		</div>
		
		<div style="height: 300px;width:500px; overflow:auto">
			<ul id="subChannelTree" class="ztree"></ul>
		</div>
		
		<div style="text-align: center;padding: 5px">
			<input type="button" id="choseChannelBtn" value="确定" onclick="chooseSubPartner()" class="input_button_1"/>&nbsp;&nbsp;&nbsp;
			<input type="button" value="取消" onclick="closeCurrentDIV('subChannelTreeDiv')" class="input_button_1"/>
		</div>
	</div>
	</body>
</html>
